import * as API from "@/api";
import {
  setStorageSync,
  getStorageSync
} from "@/libs/util";

export default {

  state: {
    userInfo: getStorageSync("userInfo") ? JSON.parse(getStorageSync("userInfo")) : "",
    token: getStorageSync("token"),
    access: getStorageSync("access"),
    messageCount: 0
  },

  mutations: {

    setUserInfo(state, userInfo) {
      state.userInfo = userInfo;
      setStorageSync("userInfo", userInfo);
    },

    setAccess(state, access) {
      state.access = access;
      setStorageSync("access", access);
    },

    setToken(state, token) {
      state.token = token;
      setStorageSync("token", token);
    }

  },

  actions: {

    //客户端单方面退出
    handleClientLogOut({
      state,
      commit
    }) {
      console.log('handleClientLogOut');
      commit("setUserInfo", "");
      commit("setToken", "");
      commit("setAccess", "");
    },
    
    //登录后缓存数据
    handleStoreLogin({state,commit},data){
      commit("setToken", data.userName);
      commit("setAccess", data.access.toString());
      commit("setUserInfo", JSON.stringify(data));
    }
    
  }
}
